/**
 * @Description
 */


class Alg2{
    //泛型方法
    public static <T extends Comparable<T>> T FindMax(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i])<0){
                max = array[i];
            }
        }
        return max;
    }
}
class Alg<T extends Comparable> {
    public T FindMax(T[]array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i])<0){
                max = array[i];
            }
        }
        return max;
    }
}
class MyArray<T>{
    public Object[] array = new Object[10];
    public void setArray(int pos,T val){
        this.array[pos] = val;
    }
    public T getArray(int pos){
        return (T)this.array[pos];
    }
}
public class Test {
    public static void main(String[] args) {
        Integer[] array = new Integer[]{1,2,3,4,5};
        Integer ret = Alg2.FindMax(array);
        /*Alg2 alg2 = new Alg2();
        Integer ret = alg2.<Integer>FindMax(array);//<>可以省略*/
        System.out.println(ret);

    }
    public static void main4(String[] args) {
        Integer[] array = new Integer[]{1,2,3,4,5};
        Alg<Integer> alg = new Alg<>();
        Integer ret = alg.FindMax(array);
        System.out.println(ret);

    }
    public static void main3(String[] args) {
            MyArray<Integer> myArray = new MyArray<>();
            myArray.setArray(0,10);
            myArray.getArray(0);
            int ret = myArray.getArray(0);
            System.out.println(ret);
    }

    public static void main2(String[] args) {
        //没有泛型的情况下需要强转
        MyArray myArray = new MyArray();
        myArray.setArray(0,"hello");
        String ret = (String) myArray.getArray(0);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        Integer a = Integer.valueOf(10);//显式装箱

        int b = 10;
        Integer c = b;//隐式装箱

        int j = Integer.valueOf(20);
        double ij = Integer.valueOf(30);//显式拆箱

        Integer f = 20;
        int d = c;//隐式拆箱

    }
}
